﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
    public class Ctbl_TopUrl:IData<tbl_TopUrl>
    {
        public Ctbl_TopUrl(String myconnecString) : base(myconnecString) { }


        protected override int InsertOnSubmit(tbl_TopUrl item, int t)
        {
            return connec.ExecuteNonQuery("ProTopUrl",CommandType.StoredProcedure, new SqlParameter("@flag", t),
                new SqlParameter("@"+tbl_TopUrl.c_content_title,item.Content_title),new SqlParameter("@"+tbl_TopUrl.c_id,item.Id),
                new SqlParameter("@"+tbl_TopUrl.c_topText,item.TopText),new SqlParameter("@"+tbl_TopUrl.c_topUrl,item.TopUrl),
                new SqlParameter("@"+tbl_TopUrl.c_Url,item.Url));
        }

        public override List<tbl_TopUrl> GetAll(tbl_TopUrl item)
        {
            throw new NotImplementedException();
        }

        public override tbl_TopUrl GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p=>p.Id==Convert.ToInt32(id));
        }

        public override tbl_TopUrl GetItem(IDataReader dr)
        {
            tbl_TopUrl obj = new tbl_TopUrl();
            obj.Content_title = dr[tbl_TopUrl.c_content_title].ToString();
            obj.Id = Convert.ToInt32(dr[tbl_TopUrl.c_id]);
            obj.TopText = dr[tbl_TopUrl.c_topText].ToString();
            obj.TopUrl = dr[tbl_TopUrl.c_topUrl].ToString();
            obj.Url = dr[tbl_TopUrl.c_Url].ToString();
            return obj;
        }


        public override List<tbl_TopUrl> GetAll()
        {
            return GetAll("select * from "+tbl_TopUrl.b_tbl_TopUrl,CommandType.Text);
        }
    }
}
